#include<bits/stdc++.h>
using namespace std;
class CPoint
{
private:
    int x,y;
public:
    CPoint(int _x=0,int _y=0):x(_x),y(_y){}
    int getX()const
    {
        return x;
    }
    int getY()const
    {
        return y;
    }
};
class CRectangle
{
private:
    CPoint leftPoint,rightPoint;
public:
    CRectangle(int x1,int y1,int x2,int y2):leftPoint(x1,y1),rightPoint(x2,y2){}
    bool operator>(const CPoint& a)
    {
        int Jx=a.getX();
        int Jy=a.getY();
        return Jx>=leftPoint.getX() && Jx<=rightPoint.getX() && Jy>=rightPoint.getY() && Jy<=leftPoint.getY();
    }
    bool operator>(const CRectangle& a)
    {
        return *this>a.leftPoint && *this>a.rightPoint;
    }
    bool operator==(const CRectangle& a)
    {
        return leftPoint.getX()==a.leftPoint.getX() && leftPoint.getY()==a.leftPoint.getY() && rightPoint.getX()==a.rightPoint.getX() && rightPoint.getY()==a.rightPoint.getY();
    }
    bool operator*(const CRectangle& a)
    {
        if(*this>a.leftPoint || *this>a.rightPoint)
            return true;
        for(int i=a.leftPoint.getX();i<=a.rightPoint.getX();++i)
        {
            for(int j=a.rightPoint.getY();j<=a.leftPoint.getY();++j)
            {
                if(*this>CPoint(i,j))
                    return true;
            }
        }
        return false;
    }
    operator int()
    {
        return (rightPoint.getX()-leftPoint.getX())*(leftPoint.getY()-rightPoint.getY());
    }
    friend ostream& operator<<(ostream& os,const CRectangle& a);
};
ostream& operator<<(ostream& os,const CRectangle& a)
{
    os<<a.leftPoint.getX()<<" "<<a.leftPoint.getY()<<" "<<a.rightPoint.getX()<<" "<<a.rightPoint.getY();
    return os;
}
int main()
{
    int t, x1, x2, y1, y2;
    cin >> t;
    while (t--)
    {
        // 矩形1的左上角、右下角
        cin >> x1 >> y1 >> x2 >> y2;
        CRectangle rect1(x1, y1, x2, y2);
        // 矩形2的左上角、右下角
        cin >> x1 >> y1 >> x2 >> y2;
        CRectangle rect2(x1, y1, x2, y2);
        // 输出矩形1的坐标及面积
        cout << "矩形1:" << rect1 << " " << (int)rect1 << endl;
        // 输出矩形2的坐标及面积
        cout << "矩形2:" << rect2 << " " << (int)rect2 << endl;
        if (rect1 == rect2)
        {
            cout << "矩形1和矩形2相等" << endl;
        }
        else if (rect2 > rect1)
        {
            cout << "矩形2包含矩形1" << endl;
        }
        else if (rect1 > rect2)
        {
            cout << "矩形1包含矩形2" << endl;
        }
        else if (rect1 * rect2)
        {
            cout << "矩形1和矩形2相交" << endl;
        }
        else
        {
            cout << "矩形1和矩形2不相交" << endl;
        }
        cout << endl;
    }
    return 0;
}